﻿using System.ComponentModel;
using VisionDesigner.EdgePairFlawInsp;
using VM.Common.Helper;

namespace Plugin.Defect
{
    [Serializable]
    public class ParamModel : NotifyPropertyBase
    {
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {
              { "最强边缘", "Best" },
            { "第一个边缘", "First" },
            { "最后一个边缘", "Last" },
            { "由黑到白边", "BlackToWhite" },
             { "由白到黑边", "WhiteToBlack" },
        };

        #region 高精度匹配参数

        private int _MaxFlawNum = 500;
        public int MaxFlawNum
        {
            get
            {
                return _MaxFlawNum;
            }
            set
            {
                Set(ref _MaxFlawNum, value);
                ParamInt["MaxFlawNum"] = value;
            }
        }

        private int _EdgePairIdealWidth = 30;
        public int EdgePairIdealWidth
        {
            get
            {
                return _EdgePairIdealWidth;
            }
            set
            {
                Set(ref _EdgePairIdealWidth, value);
                ParamInt["EdgePairIdealWidth"] = value;
            }
        }
        private int _CaliperWidth = 5;
        public int CaliperWidth
        {
            get
            {
                return _CaliperWidth;
            }
            set
            {
                Set(ref _CaliperWidth, value);
                ParamInt["CaliperWidth"] = value;
            }
        }
        private int _CaliperHeight = 50;
        public int CaliperHeight
        {
            get
            {
                return _CaliperHeight;
            }
            set
            {
                Set(ref _CaliperHeight, value);
                ParamInt["CaliperHeight"] = value;
            }
        }


        private Dictionary<string, int> _paramInt = new Dictionary<string, int>();
        public Dictionary<string, int> ParamInt
        {
            get { return _paramInt; }
            set { Set(ref _paramInt, value); }
        }

        private Dictionary<string, double> _paramDouble = new Dictionary<string, double>();
        public Dictionary<string, double> ParamDouble
        {
            get { return _paramDouble; }
            set { Set(ref _paramDouble, value); }
        }

        private Dictionary<string, Array> _paramArray = new Dictionary<string, Array>();
        public Dictionary<string, Array> ParamArray
        {
            get { return _paramArray; }
            set { Set(ref _paramArray, value); }
        }

        private Dictionary<string, object> _paramEnum = new Dictionary<string, object>();
        public Dictionary<string, object> ParamEnum
        {
            get { return _paramEnum; }
            set { Set(ref _paramEnum, value); }
        }

        #endregion

        public ParamModel()
        {
            // 整型数据
            ParamInt.Add("MaxFlawNum", MaxFlawNum);
            ParamInt.Add("EdgePairIdealWidth", EdgePairIdealWidth);
            ParamInt.Add("CaliperWidth", CaliperWidth);
            ParamInt.Add("CaliperHeight", CaliperHeight);


            //  Enum数据
            ParamArray.Add("FindMode", Enum.GetValues(typeof(FindMode)));
            ParamEnum.Add("FindMode", FindMode.Best);
        }

        public void UpdateParam(CEdgePairFlawInspTool cHPFeaturePatMatchTool)
        {
            // 整型数据
            foreach (var pair in ParamInt)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                cHPFeaturePatMatchTool.SetRunParam(key, value);
            }

            // 浮点型数据
            foreach (var pair in ParamDouble)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                cHPFeaturePatMatchTool.SetRunParam(key, value);
            }

            // Enum数据
            foreach (var pair in ParamEnum)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                if (ParamMap.ContainsKey(value))
                {
                    cHPFeaturePatMatchTool.SetRunParam(key, ParamMap[value]);
                }
            }
        }

    }

    /// <summary>
    /// 匹配极性模式
    /// </summary>
    [Serializable]

    public enum FindMode
    {
        [Description("最强边缘")]
        Best,

        [Description("第一个边缘")]
        First,

        [Description("最后一个边缘")]
        Last,



    }
}
